<%@page import="org.springframework.web.servlet.mvc.support.RedirectAttributes"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>管理考试科目</title>
	</head>

	<body class="skin-2">
			<div class="main-content">
				<!-- #section:basics/content.breadcrumbs -->
				<div class="breadcrumbs" id="breadcrumbs">
					<script type="text/javascript">
						try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
					</script>

					<ul class="breadcrumb">
						<li>
							<i class="ace-icon fa fa-home home-icon"></i>
							<a href="subjects">管理考试科目</a>
						</li>
					</ul><!-- /.breadcrumb -->

					<!-- #section:basics/content.searchbox -->
					<div class="nav-search" id="nav-search">
						<form class="form-search">
							<span class="input-icon">
								<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
								<i class="ace-icon fa fa-search nav-search-icon"></i>
							</span>
						</form>
					</div><!-- /.nav-search -->

					<!-- /section:basics/content.searchbox -->
				</div>

				<!-- /section:basics/content.breadcrumbs -->
				<div class="page-content">
					<!-- #section:settings.box -->
					<div class="ace-settings-container" id="ace-settings-container">
						<div class="btn btn-app btn-xs btn-warning ace-settings-btn" id="ace-settings-btn">
							<i class="ace-icon fa fa-cog bigger-150"></i>
						</div>

						<div class="ace-settings-box clearfix" id="ace-settings-box">
							<div class="pull-left width-50">
								<!-- #section:settings.skins -->
								<div class="ace-settings-item">
									<div class="pull-left">
										<select id="skin-colorpicker" class="hide">
											<option data-skin="no-skin" value="#438EB9">#438EB9</option>
											<option data-skin="skin-1" value="#222A2D">#222A2D</option>
											<option data-skin="skin-2" value="#C6487E">#C6487E</option>
											<option data-skin="skin-3" value="#D0D0D0">#D0D0D0</option>
										</select>
									</div>
									<span>&nbsp; Choose Skin</span>
								</div>

								<!-- /section:settings.skins -->

								<!-- #section:settings.navbar -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-navbar">
									<label class="lbl" for="ace-settings-navbar"> Fixed Navbar</label>
								</div>

								<!-- /section:settings.navbar -->

								<!-- #section:settings.sidebar -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-sidebar">
									<label class="lbl" for="ace-settings-sidebar"> Fixed Sidebar</label>
								</div>

								<!-- /section:settings.sidebar -->

								<!-- #section:settings.breadcrumbs -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-breadcrumbs">
									<label class="lbl" for="ace-settings-breadcrumbs"> Fixed Breadcrumbs</label>
								</div>

								<!-- /section:settings.breadcrumbs -->

								<!-- #section:settings.rtl -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-rtl">
									<label class="lbl" for="ace-settings-rtl"> Right To Left (rtl)</label>
								</div>

								<!-- /section:settings.rtl -->

								<!-- #section:settings.container -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-add-container">
									<label class="lbl" for="ace-settings-add-container">
										Inside
										<b>.container</b>
									</label>
								</div>

								<!-- /section:settings.container -->
							</div><!-- /.pull-left -->

							<div class="pull-left width-50">
								<!-- #section:basics/sidebar.options -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-hover">
									<label class="lbl" for="ace-settings-hover"> Submenu on Hover</label>
								</div>

								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-compact">
									<label class="lbl" for="ace-settings-compact"> Compact Sidebar</label>
								</div>

								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-highlight">
									<label class="lbl" for="ace-settings-highlight"> Alt. Active Item</label>
								</div>

								<!-- /section:basics/sidebar.options -->
							</div><!-- /.pull-left -->
						</div><!-- /.ace-settings-box -->
					</div>
					<!-- /.ace-settings-container -->
					<!-- /section:settings.box -->
					
					<!-- 增删改查提示信息 -->
					<div id="tishi" style="background-color:#cde5c8;height:60px;margin-bottom:30px;line-height:60px;color:#128535;padding-left:50px;font-size:16px;position:relative;display:none;">
						
					</div>
					<!-- /section:settings.box -->
					<div class="page-content-area">
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<div class="row">
									<div class="col-xs-12 table-responsive">
										<button id="addSubject" class="btn btn-primary">
											<i class="ace-icon fa fa-plus align-top bigger-125"></i>
											添加考试科目
										</button>
										<div class="pull-right" style="margin-right:50px;">
											<select id="language">
												<option value="zh_CN"><spring:message code="page.index.chinese" /></option>
												<option value="en_US"><spring:message code="page.index.english" /></option>
											</select>
										</div>
										<table id="sample-table-1" class="table table-condensed table-bordered table-hover">
											<thead>
												<tr>
													<th class="center">
														<label class="position-relative">
															<input type="checkbox" class="ace" />
															<span class="lbl"></span>
														</label>
													</th>
													<th><spring:message code="subject.subId.message" /></th>
													<th><spring:message code="subject.name.message" /></th>
													<th><spring:message code="subject.description.message" /></th>
													<th><spring:message code="subject.testCount.message" /></th>
													<th><spring:message code="subject.totalTime.message" /></th>
													<th><spring:message code="subject.totalScore.message" /></th>
													<th><spring:message code="subject.status.message" /></th>
													<th><spring:message code="user.action.message" /></th>
												</tr>
											</thead>
											
											<tbody>
												<c:forEach items="${subjectList.dates}" var="subject">
													<tr>
														<td class="center">
															<label class="position-relative">
																<input type="checkbox" class="ace" value="${subject.subId}" />
																<span class="lbl"></span>
															</label>
														</td>
														<td>${subject.subId}</td>
														<td>${subject.name}</td>
														<td>${subject.description}</td>
														<td>${subject.testCount}</td>
														<td>${subject.totalTime}</td>
														<td>${subject.totalScore}</td>
														<td>
															<c:choose>
																<c:when test="${subject.status == 0}">
																	<input name="sub-status" value="0" class="ace ace-switch ace-switch-6" type="checkbox">
																	<span class="lbl"></span>
																</c:when>
																<c:when test="${subject.status == 1}">
																	<input name="sub-status" value="1" checked class="ace ace-switch ace-switch-6" type="checkbox">
																	<span class="lbl"></span>
																</c:when>
															</c:choose>
														</td>
														<td>
															<a href="javascript:void(0)" title="修改" class="btn btn-xs btn-info editSubjectbtn">
																<i class="ace-icon fa fa-pencil bigger-120"></i>
															</a>
															<a href="javascript:void(0)" title="删除" class="btn btn-xs btn-danger deleteSubjectbtn">
																<i class="ace-icon fa fa-trash-o bigger-120"></i>
															</a>
															<a href="javascript:void(0)" title="管理科目学生" class="btn btn-primary btn-xs manager-subject-user-btn">
																<i class="ace-icon fa fa-users"></i>
															</a>
														</td>
													</tr>
												</c:forEach>
												<tr>
													<td colspan="12">
														<jsp:include page="../page/page.jsp">
															<jsp:param name="url" value="subjects"/>
															<jsp:param name="items" value="${subjectList.totalSize}"/>
														</jsp:include>
													</td>
												</tr>
											</tbody>
										</table>
										<!-- 添加科目模态框 -->
										<div class="modal fade" id="addSubjectModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
										  <div class="modal-dialog" role="document">
										    <div class="modal-content">
										      <div class="modal-header">
										        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
										        <h4 class="modal-title" id="myModalLabel">添加考试科目</h4>
										      </div>
										      <div class="modal-body">
										       	<form:form id="addSubjectForm" method="post" class="form-horizontal" modelAttribute="subject">
											    	<div class="form-group">
											    		<label for="name" class="col-sm-3 control-label"><i style="color:red">* </i><b>考试科目:</b></label>
											    		<div class="col-sm-8">
											    			<form:input path="name" class="form-control" placeholder="科目名称" /><form:errors path="name" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="description" class="col-sm-3 control-label"><i style="color:red">* </i><b>描述:</b></label>
											    		<div class="col-sm-8">
											    			<form:input path="description" class="form-control" placeholder="描述信息" /><form:errors path="description" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="testCount" class="col-sm-3 control-label"><i style="color:red">* </i><b>试题数量:</b></label>
											    		<div class="col-sm-4">
											    			<form:input type="number" path="testCount" class="form-control" placeholder="试题数量" /><form:errors path="testCount" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="totalTime" class="col-sm-3 control-label"><i style="color:red">* </i><b>考试时长:</b></label>
											    		<div class="col-sm-4">
											    			<form:input type="number" path="totalTime"  class="form-control" placeholder="考试时长(分钟)" /><form:errors path="totalTime" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="totalScore" class="col-sm-3 control-label"><i style="color:red">* </i><b>总分数:</b></label>
											    		<div class="col-sm-4">
											    			<form:input type="number" path="totalScore"  class="form-control" /><form:errors path="totalScore" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="chooseC" class="col-sm-3 control-label"><i style="color:red">* </i><b>考试状态:</b></label>
											    		<div class="col-sm-4">
											    			<input id="addSubjectModalStatus" name="addSubjectModalStatus" value="0" class="ace ace-switch ace-switch-6" type="checkbox">
															<span class="lbl"></span>
															<form:input path="status" value="0" style="display:none"/>
															<form:errors path="status" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="modal-footer">
												    	<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
												    	<button class="btn btn-primary" id="addSubjectbtn">确定提交</button>
												  </div>
											    </form:form>
										      </div>
										    </div>
										  </div>
										</div><!-- 添加科目模态框END -->
										
										<!-- 修改科目信息模态框 -->
										<div class="modal fade" id="editSubjectModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
										  <div class="modal-dialog" role="document">
										    <div class="modal-content">
										      <div class="modal-header">
										        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
										        <h4 class="modal-title" id="myModalLabel">修改科目信息</h4>
										      </div>
										      <div class="modal-body">
										       	<form:form id="editSubjectForm" method="post" class="form-horizontal" modelAttribute="subject">
											    	<div class="form-group" style="display:none;">
											    		<label for="subId" class="col-sm-3 control-label"><i style="color:red"></i><b>科目编号:</b></label>
											    		<div class="col-sm-2">
											    			<form:input path="subId" class="form-control" placeholder="科目编号"  /><form:errors path="subId" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="name" class="col-sm-3 control-label"><i style="color:red">* </i><b>考试科目:</b></label>
											    		<div class="col-sm-8">
											    			<form:input path="name" class="form-control" placeholder="科目名称" /><form:errors path="name" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="description" class="col-sm-3 control-label"><i style="color:red">* </i><b>描述:</b></label>
											    		<div class="col-sm-8">
											    			<form:input path="description" class="form-control" placeholder="描述信息" /><form:errors path="description" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="testCount" class="col-sm-3 control-label"><i style="color:red">* </i><b>试题数量:</b></label>
											    		<div class="col-sm-4">
											    			<form:input type="number" path="testCount" class="form-control" placeholder="试题数量" /><form:errors path="testCount" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="totalTime" class="col-sm-3 control-label"><i style="color:red">* </i><b>考试时长:</b></label>
											    		<div class="col-sm-4">
											    			<form:input type="number" path="totalTime"  class="form-control" placeholder="考试时长(分钟)" /><form:errors path="totalTime" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="totalScore" class="col-sm-3 control-label"><i style="color:red">* </i><b>总分数:</b></label>
											    		<div class="col-sm-4">
											    			<form:input type="number" path="totalScore" class="form-control" /><form:errors path="totalScore" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="form-group">
											    		<label for="chooseC" class="col-sm-3 control-label"><i style="color:red">* </i><b>考试状态:</b></label>
											    		<div class="col-sm-4">
											    			<div id="statusDiv">
											    			
											    			</div>
															<form:input path="status" value="0" style="display:none;" />
															<form:errors path="status" cssClass="error" cssStyle="color:red" />
											    		</div>
											    	</div>
											    	<div class="modal-footer">
												    	<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
												    	<button class="btn btn-primary" id="editSubjectbtn">保存</button>
												  </div>
											    </form:form>
										      </div>
										    </div>
										  </div>
										</div><!-- 添加科目模态框END -->
										
										<!-- 删除科目信息模态框 -->
										<div class="modal fade" id="deleteSubjectModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
										  <div class="modal-dialog" role="document">
										    <div class="modal-content">
										      <div class="modal-header">
										        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
										        <h4 class="modal-title" id="myModalLabel">删除</h4>
										      </div>
										      <div class="modal-body">
										       	<b style="font-size:20px;">确定删除科目信息？</b>
										      </div>
										      <input type="hidden" id="deleteSubjectId">
										      <div class="modal-footer">
												 <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
												 <button class="btn btn-primary MDeleteSubjectbtn" >确定</button>
											  </div>
										    </div>
										  </div>
										</div><!-- 删除科目信息模态框 END-->
										
										<!-- 管理科目信息模态框 -->
										<div class="modal fade" id="managerUserSubjectModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
										  <div class="modal-dialog" role="document">
										    <div class="modal-content">
										      <div class="modal-header">
										        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
										        <h4 class="modal-title" id="subjectUserModalTitle"></h4>
										        <input type="hidden" id="managerUserSubjectModalSubjectId" value="" />
										      </div>
										      <div class="subjectUserModalContent" style="height:350px;overflow:auto;">
										       	
										      </div>
										      <div class="modal-footer">
												 <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
												 <button class="btn btn-primary managerStudentSubjectModalBtn" >保存</button>
											  </div>
										    </div>
										  </div>
										</div><!-- 管理科目信息模态框 END-->
										
									</div><!-- /.span -->
								</div><!-- /.row -->
								

								
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content-area -->
				</div><!-- /.page-content -->
			</div><!-- /.main-content -->

		<!-- basic scripts -->

		<!--[if !IE]> -->
		<script type="text/javascript">
			window.jQuery || document.write("<script src='${pageContext.request.contextPath}/static/assets/js/jquery.min.js'>"+"<"+"/script>");
		</script>

		<!-- <![endif]-->

		<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='../assets/js/jquery1x.min.js'>"+"<"+"/script>");
</script>
<![endif]-->
		<script type="text/javascript">
			if('ontouchstart' in document.documentElement) document.write("<script src='${pageContext.request.contextPath}/static/assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script src="${pageContext.request.contextPath}/static/assets/js/bootstrap.min.js"></script>

		<!-- page specific plugin scripts -->
		<script src="${pageContext.request.contextPath}/static/assets/js/jquery.dataTables.min.js"></script>
		<script src="${pageContext.request.contextPath}/static/assets/js/jquery.dataTables.bootstrap.js"></script>

		<!-- ace scripts -->
		<script src="${pageContext.request.contextPath}/static/assets/js/ace-elements.min.js"></script>
		<script src="${pageContext.request.contextPath}/static/assets/js/ace.min.js"></script>

		<!-- 前端校验样式 -->
		<style>
			.error{ color:red;}
		</style>
		
		<!-- inline scripts related to this page -->
		<script type="text/javascript">
			jQuery(function($) {
				
				//点击管理科目信息,获取全部学生信息和关联科目的学生信息
				$(".manager-subject-user-btn").click(function(){
					$("#managerUserSubjectModal").modal("show");
					var html = "<div style='font-size:18px;line-height:350px;text-align:center;'>";
						html += "<img src='${pageContext.request.contextPath}/static/img/search_1.gif'></div>"
					$("#managerUserSubjectModal .subjectUserModalContent").html(html);
					var subjectId = $(this).parent().siblings().eq(1).text();
					var subjectName = $(this).parent().siblings().eq(2).text();
					$.ajax({
						type:"POST",
						url:"getAllUserAndSubjectUser",
						dataType:"json",
						data:{
							"subjectId":subjectId
						},
						success:function(data){
							var htmlString = "";
							var htmlStringChecked = "";
							var selectedUser = data.selectedUser;
							//得到所有这个科目关联的学生
							for(var i = 0; i < data.allUser.length; i++){
								var user = data.allUser[i];
								var checked = checkSelectedUser(selectedUser, user.id) ? ' checked="checked"' : '';
								if(checked != ""){
									htmlStringChecked += '<div class="checkbox">';
									htmlStringChecked += '  <label>';
									htmlStringChecked += '    <input name="subjectUser" class="ace ace-checkbox-2" type="checkbox" value="' + user.id + '" ' + checked + '>';
									htmlStringChecked += '      <span class="lbl">' + user.name + '</span>';
									htmlStringChecked += '  </label>';
									htmlStringChecked += '</div>';
								}else{
									htmlString += '<div class="checkbox">';
									htmlString += '  <label>';
									htmlString += '    <input name="subjectUser" class="ace ace-checkbox-2" type="checkbox" value="' + user.id + '" ' + checked + '>';
									htmlString += '      <span class="lbl">' + user.name + '</span>';
									htmlString += '  </label>';
									htmlString += '</div>';
								}
							}
							
							//把所有学生加入到模态框 managerUserSubjectModal 里面的内容区，即 subjectUserModalContent
							$("#managerUserSubjectModal .subjectUserModalContent").html(htmlStringChecked + " " + htmlString);
							$("#managerUserSubjectModalSubjectId").val(subjectId);
						}
					});
					$("#subjectUserModalTitle").text(subjectName);
				});
				
				//判断所有学生里面哪个是被科目关联的
				function checkSelectedUser(selectedUser, userId){
					for(var i = 0; i < selectedUser.length; i++){
						if(selectedUser[i] == userId){
							return true;
						}
					}
					return false;
				}
				
				//点击管理学生科目模态框里的保存按钮
				$(".managerStudentSubjectModalBtn").click(function(){
					var checkedSubjectUser = [];
					var subjectId = $("#managerUserSubjectModalSubjectId").val()
					for(var i = 0; i < $("#managerUserSubjectModal input[name='subjectUser']:checked").length; i++){
						checkedSubjectUser[i] = $($("#managerUserSubjectModal input[name='subjectUser']:checked")[i]).val();
					}
					$.ajax({
						type: "POST",
						url: "saveSubjectUser",
						dataType: "json",
						traditional: true,
						data:{
							"subjectId": subjectId,
							"checkedSubjectUser": checkedSubjectUser
						},
						success:function(data){
							if(data.success){
								alert("保存成功");
								$("#managerUserSubjectModal").modal("hide");
							}else{
								alert("保存失败")
							}
						}
					})
				})
				
				//点击修改科目信息按钮
				$(".editSubjectbtn").click(function(){
					$("#editSubjectModal #editSubjectForm #statusDiv").empty();
					$("#editSubjectModal #editSubjectForm #statusDiv").append("<input id='editSubjectModalStatus'" + 
							" checked name='editSubjectModalStatus' value='0' class='ace ace-switch ace-switch-6' " + 
							"type='checkbox'><span class='lbl'></span>");
					var subId = $(this).parent().siblings().eq(1).text();
					$.ajax({
						type:"GET",
						url:"subjectEdit",
						typeType:"json",
						data:{
							"subId":subId
						},
						success:function(data){
							$("#editSubjectModal #editSubjectForm input[id='subId']").val(data.subId);
							$("#editSubjectModal #editSubjectForm input[id='name']").val(data.name);
							$("#editSubjectModal #editSubjectForm input[id='description']").val(data.description);
							$("#editSubjectModal #editSubjectForm input[id='testCount']").val(data.testCount);
							$("#editSubjectModal #editSubjectForm input[id='totalTime']").val(data.totalTime);
							$("#editSubjectModal #editSubjectForm input[id='totalScore']").val(data.totalScore);
							$("#editSubjectModal #editSubjectForm input[name='status']").val(data.status);
							if(1 == data.status){
								$("#editSubjectModal #editSubjectForm #editSubjectModalStatus").attr("checked","true");
								$("#editSubjectModal #editSubjectForm #editSubjectModalStatus").val("1");
								$("#editSubjectModal #editSubjectForm input[id='status']").val("1");
							}else{
								$("#editSubjectModal #editSubjectForm #editSubjectModalStatus").removeAttr("checked");
								$("#editSubjectModal #editSubjectForm #editSubjectModalStatus").val("0");
								$("#editSubjectModal #editSubjectForm input[id='status']").val("0");
							}
						}
					})
					
					$("#editSubjectModal").modal("show");
				})
				//点击修改科目模态框里的状态按钮
				$("#editSubjectModal #editSubjectForm #statusDiv").on("click","input",function(){
					if($(this).val() == 0){
						$(this).val("1");
						$("#editSubjectModal #editSubjectForm input[id='status']").val("1");
					}else{
						$(this).val("0");
						$("#editSubjectModal #editSubjectForm input[id='status']").val("0");
					}
				})
				
				//点击修改科目模态框里的保存按钮
				$("#editSubjectModal #editSubjectForm #editSubjectbtn").click(function(){
					$.ajax({
						type:"POST",
						url:"subjectEdit",
						dataType:"json",
						data:$("#editSubjectForm").serialize(),
						success:function(data){
							if(true == data.success){
								alert("科目信息修改成功");
							}else{
								alert("科目信息修改失败");
							}
						}
					})
				})
				
				//增删改查提示方法
				function tishi(message){
					$("#tishi").html("<i class='iconfont icon-duigou1'></i> <b>Well done! </b> " + message + 
					"<span id='closetishi' style='display:inline-block;width:20px;height:20px;position:absolute;" + 
					"left:0;top:0;color:red;font-weight:bolder;background-color:#f6f2c4;line-height:20px;text-align:center;cursor:pointer;'>X</span>");
					$("#tishi").fadeIn("slow");
				}
				//点击关闭增删改查提示
				$('#closetishi').click(function(){
					$('#tishi').fadeOut("slow");
				});
				
				//添加科目前端校验
				$("#addSubjectForm,#editSubjectForm").validate({
					rules:{
						name:{
							required:true,
							minlength:2
						},
						description:{
							required:true,
							minlength:2
						},
						testCount:{
							required:true,
							min:1
						},
						totalTime:{
							required:true,
							min:1
						},
						totalScore:{
							required:true,
							min:1
						}
					},
					messages:{
						name:{
							required:"请输入科目名称",
							minlength:"科目名称长度不符,至少2个字符"
						},
						description:{
							required:"请输入科目的描述",
							minlength:"描述长度不符,至少2个字符"
						},
						testCount:{
							required:"试题数量不能为空",
							min:"试题数量不能小于1",
						},
						totalTime:{
							required:"测试时间不能为空",
							min:"测试时间不能小于1分钟",
						},
						totalScore:{
							required:"总分数不能为空",
							min:"总分数不能小于1分",
						}
					}
				})
				
				//修改科目信息前端校验
				$("#editSubjectForm").validate({
					rules:{
						name:{
							required:true,
							minlength:2
						},
						description:{
							required:true,
							minlength:2
						},
						testCount:{
							required:true,
							min:1
						},
						totalTime:{
							required:true,
							min:1
						},
						totalScore:{
							required:true,
							min:1
						}
					},
					messages:{
						name:{
							required:"请输入科目名称",
							minlength:"科目名称长度不符,至少2个字符"
						},
						description:{
							required:"请输入科目的描述",
							minlength:"描述长度不符,至少2个字符"
						},
						testCount:{
							required:"试题数量不能为空",
							min:"试题数量不能小于1",
						},
						totalTime:{
							required:"测试时间不能为空",
							min:"测试时间不能小于1分钟",
						},
						totalScore:{
							required:"总分数不能为空",
							min:"总分数不能小于1分",
						}
					}
				})
				
				//点击添加考试科目按钮
				$("#addSubject").click(function(){
					$("#addSubjectModal").modal("show");
				})
				
				//点击添加科目模态框的考试状态按钮
				$("#addSubjectModalStatus").click(function(){
					if($(this).val() == 0){
						$(this).val("1");
						$("#addSubjectForm input[id='status']").val("1");
					}else{
						$(this).val("0");
						$("#addSubjectForm input[id='status']").val("0");
					}
				})
				//点击添加模态框里的确定按钮
				$("#addSubjectbtn").click(function(){
					$.ajax({
						type:"POST",
						url:"subjectAdd",
						dataType:"json",
						data:$("#addSubjectForm").serialize(),
						success:function(data){
							if(true == data.success){
								alert("添加科目成功");
							}else{
								alert("添加科目失败");
							}
						}
					})
				})
				//修改科目考试状态
				$("input[name='sub-status']").on("change", function(){
					var subId = $(this).parent().siblings().eq(1).text();
					var statusValue = $(this).val()==0?1:0;
					//console.log($(this).val() + statusValue);
					if(statusValue == 0){
						$(this).val("0");
					}else if(statusValue == 1){
						$(this).val("1");
					}
					$.ajax({
						type:"POST",
						url:"editStatus",
						dataType:"json",
						data:{
							"subId":subId,
							"statusValue":statusValue
						},
						success:function(data){
							if(true == data.success){
								
								//alert("状态更改成功");
							}else{
								alert("状态更改失败");
							}
							//window.location.reload();
						}
					})
					
				})
				
				//点击删除按钮
				$(".deleteSubjectbtn").click(function(){
					var subId = $(this).parent().siblings().eq(1).text(); //获取ID
					$("#deleteSubjectModal #deleteSubjectId").val(subId); //给删除模态框的隐藏域赋值
					$("#deleteSubjectModal").modal("show"); 
				})
				//点击删除模态框里的确定按钮
				$("#deleteSubjectModal .MDeleteSubjectbtn").click(function(){
					var subId = $("#deleteSubjectModal #deleteSubjectId").val();
					console.log(subId);
					$.ajax({
						type:"POST",
						url:"subjectDelete",
						dataType:"json",
						data:{
							"subId":subId
						},
						success:function(data){
							$("#deleteSubjectModal").modal("hide");
							if(true == data.success){
								alert("已删除");
								window.location.reload();
							}else{
								alert("删除失败");
							}
						}
					})
				})
				//语言切换
				if("中文" == $("#language option:first-child").text()){
					$("#language option:first-child").attr("selected",true);
				}else{
					$("#language option:last-child").attr("selected",true);
				}
				$("#language").change(function(){
					var value = $(this).val();
					window.location.href = "changeLocale?localeType=" + value;
				})
				var oTable1 = 
				$('#sample-table-2')
				//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
				.dataTable( {
					bAutoWidth: false,
					"aoColumns": [
					  { "bSortable": false },
					  null, null,null, null, null,
					  { "bSortable": false }
					],
					"aaSorting": [],
			
					//,
					//"sScrollY": "200px",
					//"bPaginate": false,
			
					//"sScrollX": "100%",
					//"sScrollXInner": "120%",
					//"bScrollCollapse": true,
					//Note: if you are applying horizontal scrolling (sScrollX) on a ".table-bordered"
					//you may want to wrap the table inside a "div.dataTables_borderWrap" element
			
					//"iDisplayLength": 50
			    } );
				/**
				var tableTools = new $.fn.dataTable.TableTools( oTable1, {
					"sSwfPath": "../../copy_csv_xls_pdf.swf",
			        "buttons": [
			            "copy",
			            "csv",
			            "xls",
						"pdf",
			            "print"
			        ]
			    } );
			    $( tableTools.fnContainer() ).insertBefore('#sample-table-2');
				*/
			
			
				$(document).on('click', 'th input:checkbox' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
				});
			
			
				$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
				function tooltip_placement(context, source) {
					var $source = $(source);
					var $parent = $source.closest('table')
					var off1 = $parent.offset();
					var w1 = $parent.width();
			
					var off2 = $source.offset();
					//var w2 = $source.width();
			
					if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
					return 'left';
				}
			
			});
			$(function () {
			  $('[data-toggle="tooltip"]').tooltip()
			});
			
			
		</script>

		<!-- the following scripts are used in demo only for onpage help and you don't need them -->
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace.onpage-help.css" />
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/docs/assets/js/themes/sunburst.css" />

		<script type="text/javascript"> ace.vars['base'] = '..'; </script>
		<script src="${pageContext.request.contextPath}/static/assets/js/ace/elements.onpage-help.js"></script>
		<script src="${pageContext.request.contextPath}/static/assets/js/ace/ace.onpage-help.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/rainbow.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/generic.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/html.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/css.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/javascript.js"></script>
	</body>
</html>




